package com.shelpe.services.algorithm.mobileQscore;

import java.util.ArrayList;
import java.util.List;

import com.shelpe.services.algorithm.client.RankClient;
import com.shelpe.services.algorithm.entity.batis.Keyword;
import com.shelpe.services.algorithm.entity.batis.RptKeyword;
import com.shelpe.services.algorithm.entity.jpa.Adgroup;
import com.shelpe.services.algorithm.entity.jpa.AutoProductQueue;

import lombok.Data;

@Data
public class MobileQscoreSustainer {
	private AutoProductQueue queue;
	private Adgroup adgroup;
	
	private boolean firstRun;
	private int days;
	
	private List<Keyword> keywords;
	
	private List<RptKeyword> lastReports;
	
	
	private boolean added;
	private boolean priced;
	private boolean removed;
	
	private List<RankClient.KeywordRealtimeRankItem> ranks = new ArrayList<RankClient.KeywordRealtimeRankItem>();

	public RankClient.KeywordRealtimeRankItem findRank(long keywordID) {
		for (RankClient.KeywordRealtimeRankItem rank : this.ranks) {
			if (rank.getKeywordID() == keywordID) {
				return rank;
			}
		}
		return null;
	}
	
	public Keyword findKeyword(long keywordID){
		if(keywords != null){
			for(Keyword rpt: keywords){
				if(rpt.getKeywordId() == keywordID){
					return rpt;
				}
			}
		}
		return null;
	}
	
	public RptKeyword findLastReport(long keywordID){
		return this.findByKeywordID(this.lastReports, keywordID);
	}
	
	private RptKeyword findByKeywordID(List<RptKeyword> rpts, long keywordID){
		if(rpts != null){
			for(RptKeyword rpt: rpts){
				if(rpt.getKeywordId() != null && rpt.getKeywordId() == keywordID){
					return rpt;
				}
			}
		}
		return null;
	}
}
